#include "../mqserver/mq_binding.hpp"
#include <gtest/gtest.h>

mq::BindingManager::ptr bmp;

class BindingTest : public testing::Environment{
    virtual void SetUp() override{
        bmp = std::make_shared<mq::BindingManager>("./date/mete.db");
    }

    virtual void TearDown() override{
        bmp->clear();
    }
};

TEST(binding_test,insert_test){
    bmp->bind("exchange1","queue1","news.music.#",true);
    bmp->bind("exchange1","queue2","news.sport.#",true);
    bmp->bind("exchange2","queue1","news.music.pop",true);
    bmp->bind("exchange2","queue2","news.sport.footbal",true);
    ASSERT_EQ(bmp->size(),4);
}

// TEST(binding_test,select_test){
//     ASSERT_EQ(bmp->exists("exchange1","queue1","news.music.#"),true);
//     ASSERT_EQ(bmp->exists("exchange1","queue2","news.sport.#"),true);
//     ASSERT_EQ(bmp->exists("exchange1","queue1","news.music.pop"),true);
//     ASSERT_EQ(bmp->exists("exchange1","queue1","news.sport.football"),true);

//     mq::Binding::ptr exp = bmp->getBinding("exchange1","queue1","news.music.#");
//     ASSERT_NE(exp.get(),nullptr);//指针 要不等与 null 才正确，所以使用NE
//     ASSERT_EQ(exp->exchange_name,"exchange1");
//     ASSERT_EQ(exp->msgqueue_name,"queue1");
//     ASSERT_EQ(exp->binding_key,"news.music.#");
// }

// TEST(binding_test,select_exchange_test){
//     mq::MsgQueueBindingMap mqbm = bmp->getExchangeBindings("exchange1");
//     ASSERT_EQ(mqbm.size(),2);
//     ASSERT_NE(mqbm.find("queue1"),mqbm.end());//判断是否找到的queue1 不等与 结尾：表示存在
//     ASSERT_NE(mqbm.find("queue2"),mqbm.end());
// }
 
// TEST(binding_test,remove_queue_test){
//     bmp->removeQueueBindings("queue1");
//     ASSERT_EQ(bmp->exists("exchange1","queue1","news.music.#"),false);
//     ASSERT_EQ(bmp->exists("exchange2","queue1","news.music.pop"),false);
// }

// TEST(binding_test,remove_exchange_test){
//     bmp->removeExchangeBindings("exchange1");
//     ASSERT_EQ(bmp->exists("exchange1","queue1","news.music.#"),false);
//     ASSERT_EQ(bmp->exists("exchange1","queue2","news.sport.#"),false);
// }

// TEST(binding_test,remove_signal_test){
//     ASSERT_EQ(bmp->exists("exchange2","queue2","news.sport.football"),true);
//     bmp->unbind("exchange2","queue2");
//     ASSERT_EQ(bmp->exists("exchange2","queue2","news.sport.football"),false);
// }

// TEST(binding_test,recovery){
     
// }

//测试交换机的使用
int main(int argc,char* argv[]){
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new BindingTest);

    RUN_ALL_TESTS();

    return 0;
}

